import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css'
import 'font-awesome/css/font-awesome.css'
import './assets/css/flaticon/flaticon.css'
import './assets/css/index.css'
import {getToken} from "./assets/js/auth";

Vue.use(ElementUI)

Vue.config.productionTip = false;
const whitelist = ['/','/home','/product','/postad','/single_product','/task/toTask'];
router.beforeEach(function (to, form, next) {

  if(getToken('loginToken') !=null && getToken('login') == 'true'){
    store.dispatch('GetInfo').then(() => {
      next();
    });
  } else {
    if(whitelist.indexOf(to.path) !== -1){
      next();
    }else{
      next('/');
    }
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
